/**
 * Created by Mark_ren on 2017/6/5.
 * 苟富贵,無相忘
 */
    $(function () {
        var sel = $.Params.create();
        var item = getQueryString("item");
        var sort = getQueryString("sort");
        var titleId = getQueryString("titleId");

        getData();

        //查询
        $("#searchBtn").on("click",function(){
            var searchVal = $("#searchVal").val();
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            sel.addParams("content",searchVal);
            sel.addParams("startTime",startTime);
            sel.addParams("endTime",endTime);
            getData();
        })

        //导出
        $("#expBtn").on("click",function(){
                if(confirm("确定要导出吗！")){
                    window.location.href=getIP()+"api/v2.0/admin/comments/export/?titleId="+titleId;
                }
        })
      
        //判断checkbox状态
        $("#selAll").on("click",function () {
            if(!$(this).attr("checked")){
                $("input[type=checkbox]").attr("checked","checked")
            }else{
                $("input[type=checkbox]").removeAttr("checked");
            }
        })

     
        //删除事件
        $('#delBtn').on("click",function(){
            var pararms = getCheckData();
            delData(pararms);
        });

        //删除数据
        function delData(ids){
            if(!ids == ""){
                var del = $.Params.create();
                del.addParams("params",ids)
                del.ajax(getIP()+"api/v2.0/admin/comments/del/",function(data){
                    if(data.success){
                        alert("删除成功！");
                        getData();
                    }
                })
            }else{
                alert("请至少选择一项");
            }
        }

        //获取数据
        function getData(){
            sel.addParams("titleId",titleId);
            sel.addParams("page",0);
            sel.addParams("rows",rows);
            getPageData(sel,getIP()+"api/v2.0/admin/comments/PL",function(data){
                if(data.success){
                    var html = "";
                    $.each(data.result, function(i,val) {

                        html+='<tr role="row" class="odd">' +
                            "<td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td>";
                                if(val.member!=null){
                                    html+="<td>"+val.member.name+"</td><td>"+val.member.hospitalName+"</td>";
                                }else{
                                    html+="<td></td><td></td>";
                                }

                            html+="<td>"+val.content+"</td>"+
                            "<td>"+val.createTime+"</td>"+
                            "</tr>";
                    });
                    $("#listContainer").html(html);
                }
            })
        }
    });
